from django.contrib import admin

from . import models


# Register your models here.
admin.site.site_header = '凉水书库'
admin.site.site_title = '凉水和书库'
admin.site.index_title = '欢迎来到凉水和书库'

class HeroInfoStarkInline(admin.StackedInline):
    model = models.HeroInfo  # 指定Heroinfo为附加编辑的模块
    extra = 1  # 附加编辑的数量


class BookInfoAdmin(admin.ModelAdmin):
    # 每页显示数量
    list_per_page = 5
    # 显示的属性名,默认第一个进入下级内容
    list_display = ['__str__', 'id', 'bcomment', 'new_pub_date']
    # 过滤器,以哪个属性开始过滤
    list_filter = ['btitle', 'bread']
    # 动作执行栏在页面下方执行
    actions_on_bottom = True

    # 对允许编辑的字段进行分组
    # fields = ['btitle', 'bpub_date','bcomment', 'bread']
    # 第二种分组
    fieldsets = (
        ('基本', {'fields': ['btitle', 'bpub_date', 'is_delete', 'image']}),
        ('别改', {'fields': ['bread', 'bcomment'], 'classes': ('collapse',)})
    )
    # 配合HeroInfoStarkInline来实现图书详情管理页面加入英雄人物管理
    inlines = [HeroInfoStarkInline]


@admin.register(models.HeroInfo)
class HeroInfoAdmin(admin.ModelAdmin):
    list_display = ['__str__', 'id', 'hbook', 'hgender', 'hcomment']
    list_filter = ['hbook', 'hgender']
    search_fields = ['hname', 'hcomment']



admin.site.register(models.BookInfo, BookInfoAdmin)
# admin.site.register(models.HeroInfo)
